<?php
    if (!isset($_GET['m'])) {
        include_once 'connection/databaseHandler.php';
    }
    else {
        include_once '../connection/databaseHandler.php';
    }

        $database = new DatabaseHandler();
?>

<?php
    $dbfoto = $this->database->t_foto;
    $query_photo_role = "SELECT username_uploader FROM $dbfoto
        WHERE $dbfoto.id ='$id'";
    $result_photo_role = $this->database->execQuery($query_photo_role);
    $data=mysql_fetch_array($result_photo_role);
    if($data['username_uploader']==$this->session->username) {
?>
    <div class="ititle">Photo Tagging</div>
    <div class="tagged_user_wrap">
        <div class="ilabel"> Tagged People</div>
        <?php
            $dbtag = $this->database->t_foto_tag;
            $query_tagged = "SELECT username FROM $dbtag
            WHERE $dbtag.id_foto ='$id'";
            $result_tagged = $this->database->execQuery($query_tagged);
            $count = mysql_num_rows($result_tagged);
            for($i=1;$i<$count+1;++$i) {
                $data=mysql_fetch_array($result_tagged, MYSQL_ASSOC);
                $username = $data['username'];
        ?>
        <div class="tagged_user"> <?php echo $username; ?> </div>
        <?php
            }
        ?>
    </div>
    <?php
        $linkWall = "process/tag_photo.php";
    ?>
    <div class="field">
        <form name="tag_photo" action=<?php echo $linkWall; ?> method="get">
            <input type="hidden" name="type" value="add" />
            <input type="hidden" name="id" value=<?php echo $id; ?> />
            <div class="ilabel">Tag User</div>
            <div class="iselect">
                <select name="tag">
                    <?php
                        $dbfollow = $this->database->t_follow;
                        $query = "SELECT follow as user FROM $dbfollow
                                WHERE $dbfollow.username = '".$this->session->username."'";
                        $result = $this->database->execQuery($query);
                        $i=0;
                        while($data=mysql_fetch_array($result))
                        {
                            ++$i;
                            echo '<option value="'.$data['user']. '">'.$data['user'].'</option>';
                        }
                    ?>
                </select>
            </div>
            <div class="submit_wrap"><input type="submit" value="Tag"></div>
        </form>
    </div>
    <div class="field">
        <form name="remove_tag_photo" action=<?php echo $linkWall; ?> method="get">
            <input type="hidden" name="type" value="delete" />
            <input type="hidden" name="id" value=<?php echo $id; ?> />
            <div class="ilabel">Remove Tag</div>
            <div class="iselect">
                <select name="tag">
                    <?php
                        $result_tagged = $this->database->execQuery($query_tagged);
                        while($data=mysql_fetch_array($result_tagged))
                        {
                            echo '<option value="'.$data['username'].'">'.$data['username'].'</option>';
                        }
                    ?>
                </select>
            </div>
            <div class="submit_wrap"><input type="submit" value="Remove"></div>
        </form>
    </div>
<?php
    }
?>
